package com.ymatou.iapi.invoice.operate.testcase;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;


import com.ymatou.iapi.invoice.operate.parameter.DeductInvoiceCreateBean;
import com.ymatou.iapi.invoice.operate.service.DeductInvoiceCreateCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.YmtDeductInvoice;
import com.ymttest.database.sqlwapper.YmtDeductInvoiceWapper;
/**
*扣款单创建
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DeductInvoiceCreate{
	private static DeductInvoiceCreateCall deductinvoicecreateCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("扣款单创建");
	}

	@Before
	public void caseUp() {
		deductinvoicecreateCall=new DeductInvoiceCreateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deductinvoicecreateCall.getOpurl());
	}

	public static void  deductinvoicegetreturnerrcode(String ecode,String eMsg) throws Exception {
	    try {
	    	
			//获取返回报文的数据
		    String dataStr = deductinvoicecreateCall.getReturnData();
			//返回报文断言			
//			String accountId =  new JSONObject(dataStr).getString("AccountId");
//			Logger.verifyIsNull(accountId, "AccountId为空");
			String errCode =  new JSONObject(dataStr).getString("ErrCode");
			Logger.verifyIsContains(ecode, errCode, "ErrCode");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsContains(eMsg, errMsg, eMsg);
			String body =  new JSONObject(dataStr).getString("Body");
			Logger.verifyIsNull(body, "Body为空");
			String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
			Logger.verifyIsNull(requestUrl, "RequestUrl为空");
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(false, Success, "\"Success\":false");
	    	    	    	
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  

	}
	
	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_DeductInvoiceCreate_001() {
		Logger.start(true,"买家扣款单创建成功");
		try {
			//TODO 补全case代码
		    Map<String, Object> getMap = new HashMap<String,Object>();			
			JSONObject result=deductinvoicecreateCall.callAndGetReturnData(getMap);
			
			//获取返回的报文
			Logger.verifyNotNull(result, "返回报文非空");
			//断言报文返回true
			String success= result.getString("Success");
			Logger.verifyIsContains(true, success, "\"Success\":true");
			//断言errorMsg为空
			String errMsg=result.getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "ErrorMsg等于空");
			
			if(errMsg=="null")
			{
				
				//获得返回报文的invoiceid				
				String invoiceId=result.getString("DeductInvoiceId");
				//断言AWAccountID非空
				Logger.verifyNotNull(invoiceId, "断言DeductInvoiceId非空");
				
				//SQL ymtfp库  Ymt_DeductInvoice
				//获得数据库查询出的数据*
				YmtDeductInvoiceWapper ymtDeductInvoiceWapper = new YmtDeductInvoiceWapper();
				String deductinvoice = ymtDeductInvoiceWapper.selectByUserLoginId("lunchzhao").toString();
				
				Logger.verifyEquals( invoiceId, deductinvoice,"买家扣款单号一致");

			}
			
			

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_DeductInvoiceCreate_002() {
		Logger.start(true,"卖家扣款单创建成功");
		try {
			//TODO 补全case代码
		    Map<String, Object> getMap = new HashMap<String,Object>();
		    getMap.put("UserAccountType", 1);
		    getMap.put("UserLoginId", "wesper");
			JSONObject result=deductinvoicecreateCall.callAndGetReturnData(getMap);
			
			//获取返回的报文
			Logger.verifyNotNull(result, "返回报文非空");
			//断言报文返回true
			String success= result.getString("Success");
			Logger.verifyIsContains(true, success, "\"Success\":true");
			//断言errorMsg为空
			String errMsg=result.getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "ErrorMsg等于空");
			
			if(errMsg=="null")
			{			
				//获得返回报文的invoiceid				
				String invoiceId=result.getString("DeductInvoiceId");
				//断言AWAccountID非空
				Logger.verifyNotNull(invoiceId, "断言DeductInvoiceId非空");
				
				//SQL ymtfp库  Ymt_DeductInvoice
				//获得数据库查询出的数据
				YmtDeductInvoiceWapper ymtDeductInvoiceWapper = new YmtDeductInvoiceWapper();
				String deductinvoice = ymtDeductInvoiceWapper.selectByUserLoginId("wesper").toString();
				
				Logger.verifyEquals( invoiceId,deductinvoice, "扣款单号相同");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}